package io.yizoo.system.controller;

import com.auth0.jwt.*;
import com.auth0.jwt.algorithms.Algorithm;
import io.elm.core.CoreController;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.yizoo.system.entity.sys_dict_type;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/system/login/ai")
public class login_aiController extends CoreController {
    private static final String SECRET = "dcp.ai.token";
    @PostMapping("/getToken")
    public Object GetData() {
        Map<String, Object> playloadData = new HashMap<>();
        playloadData.put("username", "admin");
        playloadData.put("loginType", "ai");
        long tokenExpireTime = new Date().getTime() + 1000 * 60 * 60 * 24 * 90L;
        JWTCreator.Builder builder = JWT.create();
        for (Map.Entry<String, Object> entry : playloadData.entrySet()) {
            builder.withClaim(entry.getKey(), entry.getValue().toString());
        }
        builder.withExpiresAt(new Date(tokenExpireTime));
        return JsonResult(builder.sign(Algorithm.HMAC256(SECRET)));
    }
}
